Repository navigation
perf(vthread): cut the memory of a parked virtual thread from 3.8 KB to 2.6 KB - #97
Conversation
…a thread uses them
… the frozen flags into one
…it and plain frames
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
There was a problem hiding this comment.
This PR reduces parked virtual thread memory from 3.8 KB to 2.6 KB by packing yielded continuation frames into a single array, sharing two StackChunk objects across all continuations, and allocating monitor entry/wait queues lazily. The changes span the JVM monitor logic, continuation frame packing/unpacking, Object.wait/notify, and snapshot serialization. A new test VirtualPackedMix exercises the packing threshold with 2400 threads mixing synchronized, wait, and plain frames.
review-bot, model nvidia/nemotron-3-ultra-550b-a55b:free, verdict approve
What this changes
A parked virtual thread now costs 2.6 KB of JS heap instead of 3.8 KB (32% less), measured with 10,000 parked threads and the memory MXBean after
System.gc().Frame.StackChunkobjects, one for yielded and one for mounted, sinceContinuation.isEmptyandisStartedonly read them.Skynet(a million virtual threads under-Xmx1500m) still runs out of heap. The rest of a parked thread is Java objects HotSpot has too (theVirtualThread, itsContinuation, runnable, lock and container node), about 1.3 to 1.6 KB, so fitting it needs a smaller object layout.Skynet100kWithMonitorsrounds went from 16 to 22 s down to about 10 s, still over its timeout.Tests
synchronizedloop (20M) 291 / 284 ms, platform wait/notify (400,000 rounds) 636-660 / 625-659 ms.VirtualPackedMix: 2,400 virtual threads parked in synchronized methods, awaitand plain frames, past the packing threshold; output matches HotSpot.tck/JSR166TestCaseentries time out on next too).